package ObserverPattern.weatherStation;

/**
 * 具体观察者：人  订阅天气
 */
public class Person implements Observer {  
  
    Subject weatherSubject;  
    String forecatsTime, forecastMess;  
    int maxTemp, minTemp;  
    public Person(Subject weatherSubject) {  
        this.weatherSubject = weatherSubject;  
        weatherSubject.addObserver(this);  
    }
  
    @Override  
    public void update(Subject subject) {  
        if (subject instanceof WeatherStation) {  
            WeatherStation we = (WeatherStation) subject;  
            forecastMess = we.getForecastMess();  
            forecatsTime = we.getForecastTime();  
            maxTemp = we.getMaxTemperature();  
            minTemp = we.getMinTemperature();  
            System.out.println("天气预报:" + forecatsTime + "," + ",天气状况:"  
                    + forecastMess + ",最高温度:" + maxTemp + ",最低温度" + minTemp);  
        } 
    }  
}  